package xyz.xiangyushui.dao.user.member;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import xyz.xiangyushui.dao.Dao;
import xyz.xiangyushui.javaBean.renewalHistory.RenewalHistory;

public class RenewalHistoryDao extends Dao{
	public void addRenewalRecord(String userName,double money){
		db.executeUpdate("insert into renewalHistory(userName,time,money) values(?,?,?)", new Object[]{userName,new Date().getTime(),money});
	}
	
	public List<RenewalHistory> getHistory(String userName){
		List<RenewalHistory> list=new LinkedList<>();
		List<Object> l = db.excuteQuery(
				"select * from renewalHistory where userName=? ",
				new Object[] { userName });
		for (Object o : l) {
			@SuppressWarnings("unchecked")
			Map<String, Object> m = (Map<String, Object>) o;
			RenewalHistory rh=new RenewalHistory();
			rh.setTime((long) m.get("time"));
			rh.setMoney((double) m.get("money"));
			rh.setUserNamel((String) m.get("userName"));
			list.add(rh);

		}
		return list;
	}
}
